#!/bin/bash
# 打开 pages 文件夹，并创建文件
cd src/views
for file in $(ls)
do
  if [ $file == $1 ];then
      echo $1' 文件已存在, 请使用其他名字'
      exit
  fi
done
mkdir $1
cd $1

# 生成 $1.vue
echo "" > $1.vue
echo '<template>
  <div id="app">
    <slogan/>
  </div>
</template>

<script>
	import { Swipe, SwipeItem } from "vant";
  import '$1' from "@api/modules/'$1'";
  import Slogan from "@cmpt/slogan"
  export default {
    name: "App",
    data(){
        return {}
    },
    components:{
      [Swipe.name]: Swipe,
      [SwipeItem.name]: SwipeItem,
      [Slogan.name]: Slogan
    },
    methods:{},
  }
</script>

<style>

</style>' > $1.vue

# 生成 $1.js
echo "" > $1.js
echo 'document.title = "'$1'"
localStorage.setItem("MOUNT_PATH", "'$1'/'$1'")

' > $1.js

# 生成store模块
# cd ../../store/modules
# for file in $(ls)
# do
#   if [ $file == $1 ];then
#       echo $1' 文件已存在, 请使用其他名字'
#       exit
#   fi
# done
# echo "" > $1.js
# echo '// import { sms, login, UserInfo } from "@api/modules/user"
# import * as types from "../types"

# const state = {}

# const actions = {}

# const getters = {}

# const mutations = {}

# export default {
#   state,
#   actions,
#   getters,
#   mutations
# }
# ' > $1.js

# 生成api模块
cd ../../api/modules
for file in $(ls)
do
  if [ $file == $1 ];then
      echo $1' 文件已存在, 请使用其他名字'
      exit
  fi
done
echo "" > $1.js
echo 'import { get, post } from "../http"
export function '$1' () {return false;}
' > $1.js
